package com.lzy.article;

import com.lzy.api.config.RabbitMQDelayConfig;
import com.lzy.article.service.ArticleService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class RabbitMQDelayConsumer {

    @Autowired
    private ArticleService articleService;
    /**
     * 监听消息队列
     * @param payload 消息内容
     * @param message 消息对象
     */
    @RabbitListener(queues = {RabbitMQDelayConfig.QUEUE_DELAY})
    public void watchQueue(String payload, Message message) {

        System.out.println(payload);
        String routingKey = message.getMessageProperties().getReceivedRoutingKey();
        System.out.println("消费者接受延迟消息：" + new Date());

        String articleId = payload;
        articleService.updateArticleToPublish(articleId);

    }

}


